﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"
#include <GnufIDisplayManager.h>
#include <GnufINotificationCenterEventHandler.h>
#include <IUiDocumentEventHandler.h>
#include <IDocumentEventHandler.h>
#include <IUiViewEventHandler.h>

namespace gcmp {
    class IUiDocument;
}

namespace gnuf {

    class GnufProjectDisplay;
    class GnufAssetDisplay;
    class GnufDisplayManagerImpl;
    
    class GNUF_EXTENSION_EXPORT GnufDisplayManager final
        : public IDisplayManager
        , public INotificationCenterEventHandler
        , public gcmp::IUiDocumentEventHandler
        , public gcmp::IDocumentEventHandler
        , public gcmp::IUiViewEventHandler
    {
        DEFINE_CAST_DERIVED(GnufDisplayManager, IDisplayManager)
    public:
        explicit GnufDisplayManager();
        ~GnufDisplayManager();

        static const std::wstring& getIconByViewType(const std::wstring& viewType);

        const GnufProjectDisplay * activeProjectDisplay() const;
        GnufProjectDisplay * activeProjectDisplay() ;

        const GnufProjectDisplay * projectDisplayById(const int) const;
        GnufProjectDisplay * projectDisplayById(const int) ;

        void onPostActivated(const GnufProjectDisplay * const);
        
        void remove(const GnufProjectDisplay * const);

        bool closeAllProjectDisplays();

    protected:
        // Inherits from IDisplayManager...
        virtual void onSetShowingAll(bool) override;
        virtual bool onIsShowingAll() const override { return m_showingAll; }
        virtual std::list<IProjectDisplay *> onGetAllProjectDisplays()  override;
        virtual IProjectDisplay* onGetActiveProjectDisplay() override;
        virtual IProjectDisplay* onGetProjectDisplayToTile() override;
        // Inherits from INotificationCenterEventHandler...
        virtual void onEvent(gnuf::INotificationCenterEventArgs *) override;
        // Inherits from gcmp::IUiDocumentEventHandler...
        virtual void On(gcmp::IUiDocumentEventArgs *) override;
        // Inherits from gcmp::IDocumentEventHandler...
        virtual void On(gcmp::IDocumentEventArgs *) override;
        // Inherits from gcmp::IUiViewEventHandler...
        virtual void On(gcmp::IUiViewEventArgs *) override;
    private:
        GnufProjectDisplay * add(gcmp::IUiDocument *);
        bool hasOnlyOneUiDocument() const;
        
        gcmp::OwnerPtr<GnufDisplayManagerImpl> m_impl;
        bool m_showingAll;
    };
}
